Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

126
Visualizações
"Uncaught TypeError: Cannot read properties of undefined (reading 'appendChild')" when the variable is clearly defined

Learning JavaScript and HTML coding through my Senior Highschool year. I cannot figure out why this error is occurring for the life of me. Can someone help me with this? Thank you so much!

Assignment for clarity: Using only JavaScript, add a list item to the Calendar that you need to complete from your list of chores.

Code:

<!DOCTYPE html>
<html>
<head>
    <style>
        td{
            height: 150px;
            width: 150px;
        }
    </style>
</head>
    <body>
        <table border = "1" id= "chores">
            <tr id = "days">
                <th>Monday</th>
                <th>Tuesday</th>
                <th>Wednesday</th>
                <th>Thursday</th>
                <th>Friday</th>
            </tr>
            <tr id = "tasks">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
        <script>
        
            var extraTask = document.createElement("li");
            extraTask.innerHTML = "Take dishes out of dishwasher";

            var extraTaskList = document.createElement("ul");
            extraTaskList.child = extraTask;

            var tasksRow = document.getElementById("tasks").children;
            tasksRow = tasksRow[3];
            
            var tableContainer = document.getElementById("chores");
            
            
            document.tasksRow.appendChild(extraTaskList);
            
        </script>
    </body>
</html>

The visual created by the code: https://i.stack.imgur.com/GEUZG.png

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Change document.tasksRow to tasksRow.

Also, use appendChild to append an element.

<!DOCTYPE html>
<html>
<head>
    <style>
        td{
            height: 150px;
            width: 150px;
        }
    </style>
</head>
    <body>
        <table border = "1" id= "chores">
            <tr id = "days">
                <th>Monday</th>
                <th>Tuesday</th>
                <th>Wednesday</th>
                <th>Thursday</th>
                <th>Friday</th>
            </tr>
            <tr id = "tasks">
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
            </tr>
        </table>
        <script>
        
            var extraTask = document.createElement("li");
            extraTask.innerHTML = "Take dishes out of dishwasher";

            var extraTaskList = document.createElement("ul");
            extraTaskList.appendChild(extraTask);

            var tasksRow = document.getElementById("tasks").children;
            tasksRow = tasksRow[3];
            
            var tableContainer = document.getElementById("chores");
            
            
            tasksRow.appendChild(extraTaskList);
            
        </script>
    </body>
</html>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda